package org.jflame.web;

import org.jflame.commons.config.ConfigReader;
import org.jflame.commons.util.StringHelper;

import jakarta.servlet.FilterConfig;

/**
 * filter过滤器参数配置获取实现.
 * <p>
 * 如果在filter参数中未找到将向上查找ServletContext中参数
 * 
 * @author charles.zhang
 */
public class FilterParamConfig extends ConfigReader {

    protected FilterConfig filterConfig;

    public FilterParamConfig(FilterConfig filterConfig) {
        this.filterConfig = filterConfig;
    }

    @Override
    public boolean hasKey(String key) {
        return filterConfig.getInitParameter(key) == null;
    }

    @Override
    public String getValue(String configKey) {
        String value = filterConfig.getInitParameter(configKey);
        if (StringHelper.isEmpty(value)) {
            value = filterConfig.getServletContext()
                    .getInitParameter(configKey);
        }
        return value;
    }

}
